package sskj.regulatory.presentation.screen.register

import isskj.regulatory.presentation.base_mvp.api.ApiPresenter
import sskj.regulatory.data.response.session.IndexDataResponse
import sskj.regulatory.domain.interactor.UserInteractor
import javax.inject.Inject

class RegisterCompletePresenter @Inject constructor()
    : ApiPresenter<RegisterCompleteContract.View>(), RegisterCompleteContract.Presenter {


    override fun login(mobile: String, password: String) {
        view.showLoading()
        fetch(userInteractor.login(mobile, password), AUTH) {
            view.hideLoading()
            when (it.success) {
                true -> {
                    view.showLoading()
                    fetch(userInteractor.getIndexData(), AUTH) {
                        view.hideLoading()
                        view.loginOk()
                    }
                }
                else -> view.showError(it.msg)
            }
        }
    }


    override fun onRequestError(errorCode: String?, errorMessage: String?) {
        view.hideLoading()
    }
}